<?php

/**
 * This is the model class for table "tbl_customer".
 *
 * The followings are the available columns in table 'tbl_customer':
 * @property integer $id
 * @property string $c_fname
 * @property string $c_lastname
 * @property string $c_address
 * @property string $c_email
 * @property string $c_phone
 * @property string $c_purchasedate
 * @property double $c_totalmoney
 */
class Customer extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Customer the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_customer';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
		array('c_fname, c_lastname, c_phone, c_totalmoney', 'required'),
		array('c_totalmoney', 'numerical'),
		array('c_fname, c_lastname', 'length', 'max'=>50),
		array('c_address, c_email', 'length', 'max'=>128),
		array('c_phone', 'length', 'max'=>20),
		array('c_purchasedate','safe'),
		// The following rule is used by search().
		// Please remove those attributes that should not be searched.
		array('id, c_fname, c_lastname, c_address, c_email, c_phone, c_purchasedate', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bill'=>array(self::HAS_MANY, 'Bill', 'customer_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'c_fname' => 'Fist Name',
			'c_lastname' => 'Last Name',
			'c_address' => 'Address',
			'c_email' => 'Email',
			'c_phone' => 'Phone number',
			'c_purchasedate' => 'Purchase date',
			'c_totalmoney' => 'Total money',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('c_fname',$this->c_fname,true);
		$criteria->compare('c_lastname',$this->c_lastname,true);
		$criteria->compare('c_address',$this->c_address,true);
		$criteria->compare('c_email',$this->c_email,true);
		$criteria->compare('c_phone',$this->c_phone,true);
		$criteria->compare('c_purchasedate',$this->c_purchasedate,true);
		$criteria->compare('c_totalmoney',$this->c_totalmoney);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	public function behaviors()
	{
		return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior')); // 'ext' is in Yii 1.0.8 version. For early versions, use 'application.extensions' instead.
	}
}